<?php 
/*
 * 记录操作静态类
 */
class Operate{
	/**
	 * 操作记录
	 * @param <int> $uin
	 * @param <string> $content
	 */
	public static function getAdd($uin , $to_uin , $type){
		$Db = loadDB();
		$time = time();
		$insert_date = array(
			'uin' => $uin,
			'to_uin' => $to_uin,
			'type' => $type,
			'time' => $time,
		);
		//print_r($insert_date);
		$success = $Db->doInsert('statistics_operate' , $insert_date);
		return $success ? 0 : 771;
	}
	/**
	 *查询游戏的总类型
	 */
	 public static function getType(){
		$Db = loadDB();
		$type = $Db->getAll("SELECT distinct `type` FROM `statistics_operate`");
		return $type;
	 }
	 /**
	  *获取一个时间段的访问总数
	  *$last_time指定开始查询的时间
	  *$last_time指定结束查询的时间
	  */
	 public static function getDate($first_time,$last_time){
		$Db = loadDB();
		$count = $Db->getAll("SELECT type,COUNT(type) AS day_count FROM `statistics_operate` where (`time` BETWEEN $first_time and $last_time) group by type having day_count;");

		return $count;
	 }
	
	public static function getArr($array_1,$array_2,$count_name){
		for($i=0;$i<count($array_1);$i++){
			if(empty($array_2)){
				$bool=false;
			}else{
			for($j=0;$j<count($array_2);$j++){
				if($array_1[$i]['type']==$array_2[$j]['type']){
					//$rs_Count[]=array('type'=>$array_1[$i]['type'],$count_name=>$array_2[$i]['day_count']);
					$array_1[$i][$count_name]=$array_2[$j]['day_count'];
					$bool = true;
					break;
				}else{
					$bool = false;
				}				
			}
			}
			if($bool==false){
				//$rs_Count[]=array('type'=>$array_1[$i]['type'],$count_name=>"0");
				$array_1[$i][$count_name]=0;
			}
		}
		return $array_1;
	}
	/**
	 * 金钱消费
	 */
	public static function getAddConsume($uin , $type , $to_id , $num){
		$Db = loadDB();
		$time = time();
		$insert_date = array(
			'uin' => $uin,
			'type' => $type,
			'to_id' => $to_id,
			'num' => $num,
			'time' => $time,
		);
		$success = $Db->doInsert('consume_money' , $insert_date);
		return $success ? 0 : 772;
	}
	/**
	 * 查询个人消费
	 */
	public static function getAllConsume($uin){
		$Db = loadDB();
		$type = $Db->getAll("SELECT * FROM `consume_money` WHERE `uin` = {$uin} ORDER BY time DESC");
		return $type;
	}
}
# end of script